package com.qimingyu.linkedlist.linkedreverse.reverseprint;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ReversPrint {
    public int[] reversePrint(ListNode head) {
        //指针指向头结点
        ListNode p1 = head;
        ListNode p2 = head;
        int index = 0;
        while (p1 != null) {
            p1 = p1.next;
            index++;
        }
        int list[] = new int[index];
        while (p2 != null) {
            list[index - 1] = p2.val;
            p2 = p2.next;
            index--;
        }
        return list;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5, null)))));
        System.out.println(Arrays.toString(new ReversPrint().reversePrint(head)));
    }
}
